export default {
  computed: {
    request() {
      return this.store.request
    }
  },
  methods: {
    filterParam(data) {
      const _filterParam = [data => {
        const obj = {}
        for (const k in data) {
          if (data[k] !== undefined && data[k] !== '') {
            obj[k] = data[k]
          }
        }
        return obj
      }]
      return _filterParam.reduce((data, fn) => fn(data), data)
    },
    getNextNode(params) {
      return this.request({
        url: this.getNextNodeUrl,
        method: 'get',
        params
      })
    },
    getNodeInfo(params) {
      return this.request({
        url: this.getNodeInfoUrl,
        method: 'get',
        params
      })
    },
    add(ruleForm) {
      return this.request({
        url: this.addUrl,
        method: 'post',
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        data: this.filterParam(ruleForm)
      })
    },
    update(ruleForm) {
      return this.request({
        url: this.updateUrl,
        method: 'post',
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        data: ruleForm
      })
    },
    del(params) {
      return this.request({
        url: this.delUrl,
        method: 'post',
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        data: params
      })
    },
    delList(params) {
      return this.request({
        url: this.delListUrl,
        method: 'post',
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        data: params
      })
    },
    check(params) {
      return this.request({
        url: this.url,
        method: 'get',
        params
      })
    }
  }
}
